const Router = require('koa-router')
const jwt = require('koa-jwt')
const router = new Router({ prefix: '/topics' })
const {
  checkTopicExist,
  find,
  findById,
  create,
  update,
  listTopicsFollowers,
  listQuestions
} = require('../controllers/topics')
const { SECRET } = require('../config')
const auth = jwt({ secret: SECRET })
// 获取话题列表
router.get('/', find)
// 获取指定话题
router.get('/:id', checkTopicExist, findById)
// 新建话题
router.post('/', auth, create)
// 修改指定话题
router.patch('/:id', auth, checkTopicExist, update)
// 获取某个话题的关注用户列表
router.get('/:id/followers', checkTopicExist, listTopicsFollowers)
// 获取某个话题下的问题列表
router.get('/:id/questions', checkTopicExist, listQuestions)
module.exports = router
